package com.usian.controller;


import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentService;
import com.usian.utils.AdNode;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("service/contentCategory/")
public class ConcentController {

    @Autowired
    private ContentService contentService;

    /**
     * 查询内容分类管理
     * @param id
     * @return
     */
    @RequestMapping("selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam(defaultValue = "0") Integer id){
        return contentService.selectContentCategoryByParentId(id);
    }

    /**
     * 添加内容分类管理
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("insertContentCategory")
    public Integer insertContentCategory(@RequestParam Integer parentId,@RequestParam String name){
        return contentService.insertContentCategory(parentId,name);
    }

    /**
     * 修改内容分类管理
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("updateContentCategory")
    public Integer updateContentCategory(@RequestParam Integer id, @RequestParam String name){
        return contentService.updateContentCategory(id,name);
    }

    /**
     * 删除内容分类管理
     * @param categoryId
     * @return
     */
    @RequestMapping("deleteContentCategoryById")
    public Integer deleteContentCategoryById(@RequestParam Integer categoryId){
        return contentService.deleteContentCategoryById(categoryId);
    }

    /**
     * 查询广告信息
     * @param categoryId
     * @return
     */
    @RequestMapping("selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam
                                                         Integer page, @RequestParam Integer rows, @RequestParam Long categoryId){
        return contentService.selectTbContentAllByCategoryId(page,rows,categoryId);
    }

    /**
     * 添加tbcontent
     * @param tbContent
     * @return
     */
    @PostMapping("insertTbContent")
    Integer insertTbContent(@RequestBody TbContent tbContent){
        return contentService.insertTbContent(tbContent);
    }


    /**
     * 查询首页大广告位
     */
    @RequestMapping("selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
        return contentService.selectFrontendContentByAD();
    }
}
